GlideDate in Servicenow

  • gs.print(new GlideDateTime("2011-08-01 12:00:00").getDate());

    var tt=new GlideDateTime().getDate();
    gs.print(tt);

    var ss=new GlideDateTime("2017-11-04 12:00:00").getDate();
    gs.print(ss);

    gs.print(Date());

    .....................................................................................

    var g = new GlideDate();
    g.setValue('2015-01-01');
    gs.info(g);

    var gDT = new GlideDateTime(g);
    gs.info(gDT);

    ............................................................................................................................

    var gdt1 = new GlideDateTime("2016-05-15");
    var gdt2 = new GlideDateTime(gs.now());
    var dur = new GlideDuration();

    var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
    var temp = dur.getDisplayValue()
    gs.print(temp);

    var r= parseInt(temp);
    if(r==30 || r==60 || r==90)
    {
    gs.print("trigger");
    }
    else
    {
    gs.print("no");
    }

    ........................................................................................................................................................

     

    var gr = new GlideRecord('incident');
    gr.get('784b900d4f4533001a0f45dba310c713');
    var open= gr.opened_at;
    var gdt = new GlideDateTime(open);
    gdt.addDays(14);
    var due_date = gdt;

    gs.print("Due Date After 14 days"+due_date);

    gs.print("Numaric value for Open date"+gr.opened_at.dateNumericValue());

     

    gs.print("Open Date"+gr.opened_at);

    var tempp=gr.opened_at.dateNumericValue()+ 60000;

    gs.print("final numaric value"+tempp);

    gr.opened_at.setDateNumericValue(tempp);

    gs.print("Addding 60000 to Open date"+gr.opened_at.getValue());

     

    ..............................................................................................................................

    var gdt1 = new GlideDateTime("2019-04-24");

    gs.print(gdt1);

    var gtime1 = new GlideTime();
    gtime1.setValue("00:00:20");
    gdt1.add(gtime1);

    gs.print(gdt1);

     

    ............................................................................................................................................

    Javascript will not able give you the result without using time function

    var a = new Date('2013-11-05');
    var b = new Date('2013-11-05');

    if(a == b) {
    console.info("a equals b");
    }
    else {
    console.log("a NOT equals b");
    }

    if(a.getTime() == b.getTime()) {
    console.info("a equals b");
    }
    else {
    console.log("a NOT equals b");
    }